/**
 * tc管理初始化
 */
var Tc = {
    id: "TcTable",	//表格id
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1
};

/**
 * 初始化表格的列
 */
Tc.initColumn = function () {
    return [
        {field: 'selectItem', radio: true},
        {title: '', field: 'id', visible: false, align: 'center', valign: 'middle', width: '50px'},
        {title: 'tc姓名', field: 'tcName', align: 'center', valign: 'middle', sortable: true},
        {title: '电话', field: 'tcPhone', align: 'center', valign: 'middle', sortable: true},
        {
            title: '性别', field: 'tcSex', align: 'center', valign: 'middle', sortable: true,
            formatter: function (value, row, index) {
                if (value == 1) {
                    return "男";
                } else if (value == 2) {
                    return "女"
                } else {
                    return "未知"
                }
            }
        },
        {title: '生日', field: 'tcBirthday', align: 'center', valign: 'middle', sortable: true},
        {title: '备注', field: 'remarks', align: 'center', valign: 'middle', sortable: true}];
};

Tc.check = function () { // 检查是否选中
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if (selected.length == 0) {
        Feng.info("请先选中表格中的某一记录！");
        return false;
    } else {
        Tc.seItem = selected[0];
        return true;
    }
};

/**
 * 点击添加
 */
Tc.openAddTc = function () {
    var index = layer.open({
        type: 2,
        title: '添加tc',
        area: ['90%', '90%'], //宽高
        fix: true, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/tc/tc_add'
    });
    this.layerIndex = index;
};

/**
 * 打开查看详情
 */
Tc.openTcDetail = function () {
    if (this.check()) {
        var index = layer.open({
            type: 2,
            title: 'tc详情',
            area: ['90%', '90%'], //宽高
            fix: true, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/tc/tc_update/' + Tc.seItem.id
        });
        this.layerIndex = index;
    }
};

/**
 * 删除部门
 */
Tc.delete = function () {
    if (this.check()) {
        var ajax = new $ax(Feng.ctxPath + "/tc/delete/" + this.seItem.id, function (data) {
            Feng.success("删除成功!");
            Tc.table.refresh();
        }, function (data) {
            Feng.error("删除失败!" + data.responseJSON.message + "!");
        });
        ajax.start();
    }
};


/**
 * 查询表单提交参数对象
 * @returns {{}}
 */
Tc.formParams = function () {
    var queryData = {};
    queryData['tcName'] = $("#tcName").val();
    queryData['tcPhone'] = $("#tcPhone").val();
    return queryData;
}
Tc.resetSearch = function () {
    $("#tcName").val("");
    $("#tcPhone").val("");
    Tc.search();
};
/**
 * 查询列表
 */
Tc.search = function () {
    Tc.table.refresh({query: Tc.formParams()});
};

$(function () {
    var defaultColunms = Tc.initColumn();
    var table = new BSTable(Tc.id, "/tc/list", defaultColunms);
    table.setPaginationType("server");
    table.setQueryParams(Tc.formParams());
    Tc.table = table.init();
    Tc.table = table;
});
